<?php
namespace Site\Controller;
use Common\Controller\AdminbaseController;
class WebinfoController extends AdminbaseController 
{   
    protected $webinfoFile;
	public function _initialize()
	{
        //parent::_initialize();
        $this->webinfoFile = "Config/web_config.php";
	}

	public function index()
	{
		$this->edit();
	}

    public function edit()
    {
    	$webinfoObj = $this->getWebinfoObj();
    	$this->assign("webinfo",$webinfoObj);
    	$this->display("edit");
    }

    public function getWebinfoObj()
    {
       $web_config="";
       
       $fp = fopen($this->webinfoFile, "r");
        if($fp){ 
            for($i=1;! feof($fp);$i++) 
            { 
                $web_config.=fgets($fp);
            } 
        }else{
          return "打开文件失败"; 
        } 
        fclose($fp);
        $web_config=unserialize($web_config);
        return $web_config;
    }
    public function save()
    {
        $data = $_POST;
        $fp = fopen($this->webinfoFile, "w");
        if($fp){
             $data=serialize($data);
             fwrite($fp,$data);
             fclose($fp);
             $arr = array("status"=>'1',"message"=>"保存网站信息成功","url"=>"index");    
        }else{
             $arr = array("status"=>'0',"message"=>"保存网站信息失败，文件打开失败！");
        } 
        echo json_encode($arr);
    }
    
}